#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

const std::string g_pathName = "./fifo";
const int g_size = 1024;
const int g_mode = 0600; // 起始权限
const int g_defaultfd = -1;
const int g_openForWrite = O_WRONLY;
const int g_openForRead = O_RDONLY;


int openPipe(std::string name, int flag)
{
    umask(0);
    //如果读端打开，写端还没打开，读端阻塞
    int fd = open(g_pathName.c_str(), flag);
    if (fd == -1)
    {
        std::cout << name << " open fail" << std::endl;
    }
    std::cout << name << " open success" << std::endl;
    return fd;
}

void closePipe(std::string name, int fd)
{
    int n = close(fd);
    if (n == -1)
    {
        std::cout << name << " close fail" << std::endl;
    }
    else
    {
        std::cout << name << " close success" << std::endl;
    }
}